<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMapAsync"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :defaultEventKey="defaultEventKey"
      :labelWidth="75"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>w-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
      :defaultEventKey="defaultEventKey"
      :randomRowKey="true"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="120" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
                {
                  label: '应答明细',
                  visible: (scope.row.status === '05'),
                  doFunc: () => {
                    handleAction('answerdetail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="160px" :disabled="true">

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailForm.id" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="报文标识号" prop="pkgId">
              <el-input v-model="detailForm.pkgId" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="CPG日期" prop="cpgdate">
              <el-date-picker v-model="detailForm.cpgdate" style="width: 100%;" type="date" value-format="yyyyMMdd" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker v-model="detailForm.workdate" style="width: 100%;" type="date" value-format="yyyyMMdd" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="发起直接参与机构号" prop="directSender">
              <el-input v-model="detailForm.directSender" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="发起直接参与机构名称" prop="directSenderName">
              <el-input v-model="detailForm.directSenderName" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="接收直接参与机构号" prop="directRecver">
              <el-input v-model="detailForm.directRecver" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="接收直接参与机构名称" prop="directRecverName">
              <el-input v-model="detailForm.directRecverName" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="IDENTIFICATION" prop="identification">
              <el-input v-model="detailForm.identification" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原报文标识号" prop="oriPkgId">
              <el-input v-model="detailForm.oriPkgId" />
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原发起参与机构" prop="oriSender">
              <el-input v-model="detailForm.oriSender" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原报文类型" prop="oriMsgType">
              <el-input v-model="detailForm.oriMsgType" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="附言" prop="addInfo">
              <el-input type="textarea" v-model="detailForm.addInfo" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易状态" prop="status">
              <el-select style="width: 100%;" v-model="detailForm.status" placeholder="交易状态">
                <el-option
                  v-for="dict in dictMap.PKG_STATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>


    <!-- 添加或修改弹出框 -->
    <el-dialog :title="titleAnswer" :visible.sync="openAnswer" center width="1024px" append-to-body :close-on-click-modal="false">
      <el-form ref="detailAnswerForm" :model="detailAnswerForm" :rules="rules" label-width="160px" :disabled="true">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="id">
              <el-input v-model="detailAnswerForm.id" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报文标识号" prop="pkgId">
              <el-input v-model="detailAnswerForm.pkgId" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="工作日期" prop="workdate">
              <el-date-picker v-model="detailAnswerForm.workdate" style="width: 100%;" type="date" value-format="yyyyMMdd" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="原报文标识号" prop="oriPkgId">
              <el-input v-model="detailAnswerForm.oriPkgId" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="原报文类型代码" prop="oriMsgType">
              <el-input v-model="detailAnswerForm.oriMsgType" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="附言" prop="addInfo">
              <el-input type="textarea" v-model="detailAnswerForm.addInfo" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="ORG_IDENTIFICATION" prop="orgIdentification">
              <el-input v-model="detailAnswerForm.orgIdentification" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="业务处理码" prop="rspCode">
              <el-input v-model="detailAnswerForm.rspCode" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="NPC处理信息" prop="npcProcInfo">
              <el-input type="textarea" v-model="detailAnswerForm.npcProcInfo" />
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="cancelAnswer">关 闭</el-button>
      </div>
    </el-dialog>



  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";

import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import HtAmountInput from "@/views/components/HtAmountInput";
import {
  realTimePaymentRevokeQueryDetail,
  realTimePaymentRevokeQueryDetailReply,
  realTimePaymentRevokeQueryQuery,
} from "@/api/cnaps/beps/365";

export default {
  name: "RealTimePaymentRevokeQuery",
  mixins: [listPageMixin],
  components: {HtAmountInput},
  data() {
    return {
      // 查询参数
      queryParams: {
        idSeqno: undefined,
        pkgId:undefined,
        startcpgdate:undefined,
        endcpgdate:undefined,
        startworkdate: undefined,
        endworkdate: undefined,
      },
      loading: false,
      // 搜索
      defaultEventKey: "defaultEventKey",
      formOptions: [],
      //
      searchFormDictList: ["PKG_STATUS"],
      // 列信息
      regConfig: realTimePaymentRevokeQueryQuery,

      tableBindColumns: [
        { prop: 'id', align: 'center',  label: '交易流水号',width:180},
        { prop: 'cpgdate', align: 'center',  label: 'CPG日期', type:'date',width:120},
        { prop: 'workdate', align: 'center',  label: '工作日期', type:'date',width:120},
        { prop: 'pkgId', align: 'center',  label: '报文标识号',width:180},
        { prop: 'identification', align: 'center',  label: 'IDENTIFICATION',width:180},
        { prop: 'oriPkgId', align: 'center',  label: '原报文标识号',width:180},
        { prop: 'oriSender', align: 'center',  label: '原发起参与机构',width:180},
        { prop: 'oriMsgType', align: 'center',  label: '原报文类型',width:120},
        { prop: 'addInfo', align: 'center',  label: '附言',width:120},
        { prop: 'status', align: 'center',  label: '交易状态',dictCode:'PKG_STATUS' },
      ],


      dictMapAsync: {},
      // 弹出层标题
      title: "",
      titleAnswer:"",
      // 是否显示弹出层
      open: false,
      openAnswer:false,
      // 表单参数
      detailForm: {},
      detailAnswerForm: {},

      totalRecord: 0,
      totalPage: 0,
      needCount: 0,

      rules: {},
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "input",
        prop: "idSeqno",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },

      {
        type: "input",
        prop: "pkgId",
        defaultAttr: {
          size: "small",
          label: "报文标识号",
          placeholder: "请输入报文标识号",
        },
      },
      {
        type: "dates",
        nameObj: {
          startTimeName: "startcpgdate",
          endTimeName: "endcpgdate",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG日期开始", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "startworkdate",
          endTimeName: "endworkdate",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作日期开始", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
        case "answerdetail":
          this.handleAnswerDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    cancelAnswer() {
      this.openAnswer = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "实时缴款撤销申请报文查询明细";
      realTimePaymentRevokeQueryDetail(row).then((response) => {
        this.detailForm = response.result;
        this.open = true;
      }).catch(err =>{

      });
    },

    /** 详情按钮操作 */
    handleAnswerDetail(row) {
      this.titleAnswer = "实时缴款撤销申请报文查询应答明细";
      realTimePaymentRevokeQueryDetailReply(row).then((response) => {
        if(response.result!==undefined&&response.result!==null){
          this.detailAnswerForm = response.result;
        }

        this.openAnswer = true;
      }).catch(err =>{

      });
    },

  },
};
</script>
